﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using SPVisualDev.Services;
using EnvDTE80;

namespace SPVisualDev.VSAddin
{
    internal class SpecialProjectManager
    {
        private Dictionary<string, SpecialProject> m_projects = new Dictionary<string, SpecialProject>();
        private DTE2 m_dte;

        public SpecialProjectManager(DTE2 Dte)
        {
            m_dte = Dte;
        }

        public int Count
        {
            get { return m_projects.Keys.Count; }
        }

        public List<SpecialProject> GetAllSpecialProjects()
        {
            List<SpecialProject> list = new List<SpecialProject>();
            foreach (KeyValuePair<string, SpecialProject> kvp in m_projects)
            {
                list.Add(kvp.Value);
            }

            return list;
        }

        public SpecialProject GetSpecialProject(Project project)
        {
            if (project == null)
                return null;

            if (m_projects.ContainsKey(project.Name))
            {
                return m_projects[project.Name];
            }
            else
            {
                if (Common.CheckIfSpecialProject(project))
                {
                    SpecialProject specialProject = new SpecialProject(project, m_dte);
                    m_projects.Add(project.Name, specialProject);

                    return specialProject;
                }
                else
                {
                    return null;
                }
            }
        }

        public void RemoveSpecialProject(Project project)
        {
            RemoveSpecialProject(project.Name);
        }

        public void RemoveSpecialProject(string projectName)
        {
            if (m_projects.ContainsKey(projectName))
            {
                m_projects[projectName].Dispose();
                m_projects.Remove(projectName);
            }
        }

    }
}
